home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / treadmilChar.lua < prev    next >
Text File  |  2004-01-29  |  3KB  |  113 lines

  1. -- treadmil character state machine
  2. beginStateMachine()
  3.     
  4.     onEnter(function(msg)
  5.         local treadmill = getStateObjectFromID(msg.sender);
  6.         storeStateObject("treadmill", treadmill);
  7.         
  8.         if (treadmill) then
  9.             -- treadmill does still exist
  10.             if (getParent().isOneActionPointLocked(treadmill)) then
  11.                 -- action point is locked
  12.                 getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  13.                 sendMsg("emoThink", getParent().walkSO);
  14.                 exitStateMachine();
  15.             else
  16.                 getParent().lockActionPoints(treadmill);
  17.             end
  18.         else
  19.             -- treadmill does not exist anymore
  20.             getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
  21.             sendMsg("emoThink", getParent().walkSO);
  22.             exitStateMachine();
  23.         end
  24.     end )
  25.     
  26.     onExit(function(msg)
  27. --        local treadmill = retrieveStateObject("treadmill");
  28. --        getParent().stopAllActivities(treadmill);
  29. --        getParent().unlockActionPoints(treadmill);
  30. --        removeStateObject("treadmill");
  31.         
  32.         unlockAll("treadmill");    
  33.         
  34.     end )
  35.     
  36.     -- enter the treadmil
  37.     state("enter")
  38.     
  39.         onEnter(function(msg)
  40.             startAnimation("treadmilStart");
  41.             sendDelayedMsgThis("startTreadmilSound", 3000);
  42.             
  43.         end )
  44.         
  45.         onMsg("startTreadmilSound", function(msg)
  46.             getParent().playSound("treadmilOn");
  47.             getParent().playSound("treadmilFadein");
  48.             sendDelayedMsg("startTreadmilLoopSound", this, 3430);
  49.         end )
  50.             
  51.         onMsg("startTreadmilLoopSound", function(msg)
  52.             getParent().loopSound("treadmilLoop");
  53.         end )    
  54.     
  55.         onMsg("end", function(msg)
  56.             if (testCancel()) then
  57.                 setState("exit");
  58.             else
  59.                 setState("run");
  60.             end
  61.         end )    
  62.     
  63.     -- run on treadmil
  64.     state("run")
  65.     
  66.         onEnter(function(msg)
  67.             local treadmill = retrieveStateObject("treadmill");
  68.             local run = getParent().startActivity("run", treadmill);
  69.             length, scale = getActivityLength(run);
  70.             storeData("scale", scale);
  71.             print("run scale:" .. scale);
  72.             startAnimation("treadmilLoop", false, scale);
  73.             sendDelayedMsgThis("stopRun", length);
  74.         end )
  75.         
  76.         onMsg("startTreadmilLoopSound", function(msg)
  77.             getParent().loopSound("treadmilLoop");
  78.         end )    
  79.         
  80.         onMsg("stopRun", function(msg)
  81.             print("stopRun timeout");
  82.             setState("exit");
  83.         end )    
  84.     
  85.         onMsg("end", function(msg)
  86.             if testCancel()  or (not this.getParent().getCurrentActivityGain())  then
  87.                 print("stopRun getCurrentActivityGain");
  88.                 setState("exit");
  89.             else                
  90.                 startAnimation("treadmilLoop", false, retrieveData("scale", 1.0));
  91.                 --doSomething();
  92.             end
  93.         end )    
  94.         
  95.     -- exit the treadmill
  96.     state("exit")
  97.     
  98.         onEnter(function(msg)
  99.             --print("exit the treadmill");
  100.             startAnimation("treadmilExit", false, retrieveData("scale", 1.0));
  101.             getParent().stopSound("treadmilLoop");
  102.             getParent().playSound("treadmilFadeout");
  103.             local treadmill = retrieveStateObject("treadmill");
  104.             getParent().stopAllActivities(treadmill);
  105.         end )
  106.     
  107.         onMsg("end", function(msg)
  108.             setCurrentPosition();
  109.             exitStateMachine();
  110.         end )    
  111.     
  112. endStateMachine()
  113.